<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>

    <link rel="stylesheet" href="../../css/main.css" media="all">
</head>

<body>
<form class="layui-form layui-form-pane">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">对企业说：</label>
        <div class="layui-input-block">
            <textarea name="selfrecommend" placeholder="请输入自我推荐" lay-verify="required" lay-reqtext="自我推荐是必填项，岂能为空？"
                      class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <button class="layui-btn" lay-submit="" lay-filter="savepostion" style="background-color:salmon;">提交</button>
    </div>
</form>
<script src="../../libs/layui/layui.js"></script>
<script src="../../js/model.js"></script>
<script>
    let jobid;

    function initjobid(data) {
        jobid = data;
    }

    layui.use(['layer', 'jquery', 'form', 'okLayer'], function () {
        let layer = layui.layer;
        let $ = layui.jquery;
        let form = layui.form;
        let okLayer = layui.okLayer;
        //如果tpeiseid为null则关闭窗口
        if (jobid == null) {
            okLayer.greenTickMsg("数据请求出错，刷新后重试", function () {
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            });
        }
        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();
        // 获取student
        var student = JSON.parse(window.sessionStorage.getItem("student"));
        var url = ctx + "/pages/student/studentLogin.html";
        if (student == null) {
            okLayer.yellowSighMsg("登陆时间超时，请重新登录！", function () {
                window.sessionStorage.clear();
                window.open(url, "_top", "", "true");
            });
        }
        form.on('submit(savepostion)', function (data) {
            var record = new Record(null, student, new EnterpriseJob(jobid), data.field.selfrecommend);
            okLayer.confirm("一个月内只能申请20个岗位，确定要申请吗？", function () {
                $.ajax({
                    url: ctx + '/ygssecs/applypostion',
                    type: 'post',
                    data: {recordjson: JSON.stringify(record)},
                    dataType: 'json',
                    beforeSend: function () {
                        layer.load();
                    }
                }).done(function (res) {
                    layer.closeAll();
                    if (res.code == 200) {
                        okLayer.greenTickMsg(res.msg, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else {
                        okLayer.yellowSighMsg(res.msg);
                    }
                }).fail(function (error) {
                    console.error(error)
                })
            })
            return false;//阻止表单跳转
        })
    })
</script>


</body>
</html>